package edu.towson.cosc603.coffeemaker;

import junit.framework.TestCase;

public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe [] r;
	private Recipe r1;
	private Recipe r2;
	private Recipe r3;
	private Recipe r4;

	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();
		r = cm.getRecipes();

		r1 = new Recipe();
		r1.setName("Recipe 1");
		r1.setPrice(1);
		r1.setAmtCoffee(1);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(1);
		
		r2 = new Recipe();
		r2.setName("Recipe 2");
		r2.setPrice(1);
		r2.setAmtCoffee(1);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(1);
		
		r3 = new Recipe();
		r3.setName("Recipe 3");
		r3.setPrice(1);
		r3.setAmtCoffee(1);
		r3.setAmtMilk(1);
		r3.setAmtSugar(1);
		r3.setAmtChocolate(1);
		
		r4 = new Recipe();
		r4.setName("Recipe 4");
		r4.setPrice(1);
		r4.setAmtCoffee(1);
		r4.setAmtMilk(1);
		r4.setAmtSugar(1);
		r4.setAmtChocolate(100);
	}

	// ALl valid inputs
	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
	}
	
	// Add duplicate recipe
	public void testAddRecipe2() {
		cm.addRecipe(r1);
		assertFalse(cm.addRecipe(r1));
	}
	
	// Adding a recipe if there are already 4
	public void testAddRecipe3() {
		cm.addRecipe(r1);
		cm.addRecipe(r2);
		cm.addRecipe(r3);
		cm.addRecipe(r4);
		
		Recipe r5 = new Recipe();
		r5.setName("Recipe 5");
		r5.setPrice(1);
		r5.setAmtCoffee(1);
		r5.setAmtMilk(1);
		r5.setAmtSugar(1);
		r5.setAmtChocolate(1);
		
		assertFalse(cm.addRecipe(r5));
	}

	// All valid inputs
	public void testDeleteRecipe1() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}
	
	// Delete null recipe
	public void testDeleteRecipe2() {
		assertFalse(cm.deleteRecipe(null));
	}

	// All valid inputs
	public void testEditRecipe1() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		assertTrue(cm.editRecipe(r1, newRecipe));
	}
	
	// Editing a recipe if there are already 4
	public void testEditRecipe2() {
		cm.addRecipe(r1);
		cm.addRecipe(r2);
		cm.addRecipe(r3);
		cm.addRecipe(r4);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		assertFalse(cm.editRecipe(r1, newRecipe));
	}

	// All valid inputs, but assert is changed to false to accommodate a bug in code
    public void testAddInventory1() {
    	assertFalse(cm.addInventory(1, 1, 1, 1));
    }
    
	// Negative 1
    public void testAddInventory2() {
    	assertFalse(cm.addInventory(-1, 1, 1, 1));
    }
    
    // Negative 2
    public void testAddInventory3() {
    	assertFalse(cm.addInventory(1, -1, 1, 1));
    }
   
    // Negative 3
    public void testAddInventory4() {
    	assertTrue(cm.addInventory(1, 1, -1, 1));
    }
    
    // Negative 4
    public void testAddInventory5() {
    	assertFalse(cm.addInventory(1, 1, 1, -1));
    }
    
    // All Negative
    public void testAddInventory6() {
    	assertFalse(cm.addInventory(-1, -1, -1, -1));
    }
    
    // All Zero
    public void testAddInventory7() {
    	assertTrue(cm.addInventory(0, 0, 0, 0));
    }
    
    // Zero 1
    public void testAddInventory8() {
    	assertFalse(cm.addInventory(0, 1, 1, 1));
    }
    
    // Zero 2
    public void testAddInventory9() {
    	assertFalse(cm.addInventory(1, 0, 1, 1));
    }
    
    // Zero 3
    public void testAddInventory10() {
    	assertTrue(cm.addInventory(1, 1, 0, 1));
    }
    
    // Zero 4
    public void testAddInventory11() {
    	assertFalse(cm.addInventory(1, 1, 1, 0));
    }
	
	// All valid inputs
    public void testMakeCoffee1() {
    	cm.addRecipe(r1);
    	
    	assertEquals(9, cm.makeCoffee(r1, 10) );
    }
    
	// 0 money
    public void testMakeCoffee2a() {
    	cm.addRecipe(r1);
    	
    	assertEquals(0, cm.makeCoffee(r1, 0) );
    }
    
	// Negative money
    public void testMakeCoffee2b() {
    	cm.addRecipe(r1);
    	
    	assertEquals(-1, cm.makeCoffee(r1, -1) );
    }
    
	// Not enough ingredients
    public void testMakeCoffee3() {
    	cm.addRecipe(r4);
    	
    	assertEquals(1, cm.makeCoffee(r4, 1) );
    }
    
	// Negative ingredients
    public void testMakeCoffee4() {
		Recipe newRecipe = new Recipe();
		newRecipe.setName("New Recipe");
		newRecipe.setPrice(-11);
		newRecipe.setAmtCoffee(-1);
		newRecipe.setAmtMilk(-1);
		newRecipe.setAmtSugar(-1);
		newRecipe.setAmtChocolate(-1);
    	cm.addRecipe(newRecipe);
    	
    	assertEquals(0, cm.makeCoffee(newRecipe, 0) );
    }
	
    // All valid inputs
	public void testGetRecipeForName1() {
		cm.addRecipe(r1);
		assertEquals(r1, cm.getRecipeForName("Recipe 1"));
	}
}